package com.bdqn.demo05;

/**
 * 单例模式02 (饿汉式)
 *
 * @author LILIBO
 * @since 2021-12-02
 */
public class Singleton02 {

    private static Singleton02 singleton = new Singleton02(); // 饿汉式

    /**
     * 将构造方法私有化
     */
    private Singleton02() {

    }

    /**
     *
     * @return
     */
    public static Singleton02 getInstance() {
        add(); // 每次加1
        return singleton;
    }

    /**
     * 记录网站访问人数
     */
    private static int num = 0;

    private static void add() {
        num++;
    }

    public int count() {
        return num;
    }
}
